<?php
/**
 * 省市区表内置数据
 */
namespace BaseBundle\DataFixtures\ORM;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadAreaData implements FixtureInterface, ContainerAwareInterface
{

    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * {@inheritdoc}
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $data = $this->container->get('services.files')->readToJson('app' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'area.json');

        $conn = $this->container->get('database_connection');

        foreach ($data as $key=>$value){
            $conn->insert('area', $value);
        }
    }

}